# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Romain Gautier <romain.gautier@nimamoh.com>

pkgname=kotlin
pkgver=1.9.20
pkgrel=1
pkgdesc='Statically typed programming language that can interoperate with Java'
arch=(any)
url='https://kotlinlang.org/'
license=(APACHE custom)
depends=('java-environment>=8')
makedepends=(setconf)
source=("https://github.com/JetBrains/kotlin/releases/download/v${pkgver/_/-}/kotlin-compiler-${pkgver/_/-}.zip")
sha512sums=('779a54b2e704c8e3844b80fc31a7c6e7b878edad05a42f470c4eb38f2118e02fc94702d25b677d1734f335acccd6e5cfcfa33ae0e406d49a88ad51b772877265')
b2sums=('e1d1ffa8db589f5d6739206c5df0a4efec9ad5da2c6dad6cb877988480474c6f705f64dde15e2e14c22f7d5ce2a326e55e664cf584d116398455e02c2a5f0dcd')

prepare() {
  cd ${pkgname}c/bin

  setconf kotlin      DIR         /usr/bin
  setconf kotlinc-js  DIR         /usr/bin
  setconf kotlinc-jvm DIR         /usr/bin
  setconf kotlinc     KOTLIN_HOME /usr/share/$pkgname
}

package() {
  cd ${pkgname}c

  # executables
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlin
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlinc
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlinc-js
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlinc-jvm

  # jar files
  cd lib
  install -d "$pkgdir/usr/share/$pkgname/lib"
  for jar in *.jar; do
    install -Dm644 "$jar" "$pkgdir/usr/share/$pkgname/lib"
  done

  # licenses
  cd "$srcdir/${pkgname}c/license"
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  install -Dm644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname"
  install -Dm644 NOTICE.txt "$pkgdir/usr/share/licenses/$pkgname"
  for txt in third_party/*.txt; do
    install -Dm644 "$txt" "$pkgdir/usr/share/licenses/$pkgname"
  done

  # build.txt must be installed for for "-version" to work
  cd $srcdir/${pkgname}c
  install -Dm644 build.txt "$pkgdir/usr/share/$pkgname"
}

# getver: github.com/JetBrains/kotlin/releases/latest
